Part Number Hot Search : 
D13009 X24008 24LQXIT 6248NTDA CD2025 HE3C543 GCM1555 H0010
Product Description
Full Text Search
 

To Download SH6610 Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  SH6610 instructions introduction SH6610 instructions introduction sino w ealth electronic (shanghai) l t d. ve r 1 . 0 1 / 3 6 http://
s h 6 6 1 0 i n s t r u c t i o n s i n t r o d u c t i o n analysis of SH6610 instructions the following a r e SH6610 in struct ions, catego rized a nd ex plaine d acco rdin g to their re spe c tive function s. wh en you nee d an instruct i o n for a certai n function, you can loo k up the instru ctio n in its function categ o ry. you?d better browse throu gh all the instru ction s listed here, beca u s e even thoug h you can?t rememb er all of them at once, you can still have an impre s sion to remind you of such inst ruct ion when need ed. some people don ?t even know about som e very good inst ruction s that he can us e, just beca u se he didn?t browse throu gh all of them. this igno ra nce may cau s e consi d e r abl e wa ste of spa c e on a syste m without a b i g enou gh rom , which is so reg r ettable. i will ex plain as simply a s possibl e to i m prove yo u r learning effici ency. of co urse, it is n o r mal to u nde rsta nd o r re membe r o n ly part of the conte n ts afte r re adin g on ce. and you are ce rtain of ten reve rt to this bo ok be cau s e it i s a colle ct ion of i n st r u ct io ns. instructions instru ction i s a se rie s of cod e s that can be re cog n ize d by cp u, and th en cpu will ope rate a c cording to the gi ven instructio n. opera n d ap art from i n structio ns t o tell cpu how to op erate, the ope ration o b je ct must be desi gnate d . the o b je ct for cp u to o p e rate with i s calle d opera n d . therefo r e, a co mplet e instructio n must incl ude two items, both inst r u ct io n and ope ran d . form at of SH6610 in stru cti ons instru ction [operand 1], [operand 2] of the above, items insi de [ ] are used acco rdin g to nature of the instructio n. some instructio ns requi re only o ne ope ra nd, while som e requi re two. in stru ction a nd ope ran d sh all be se p a rate d by a sp a c e, a nd ope ra nd s shall b e se p a rated fro m ea ch othe r by a ?,?. execution t i me of instru ction executio n time for SH6610 in stru cti ons i s one in stru ction cy cl e , which is on e fourth of the system worki ng freq uen cy . ve r 1 . 0 2 / 3 6
s h 6 6 1 0 i n s t r u c t i o n s i n t r o d u c t i o n 1-1 instruction categories accordi ng to their fun c tion s, SH6610 in st ru ction s ca n be cla s sified i n to four categ o rie s : z arithmetic o p eratio n instru ction s i. addition: adc d adcm d ad d d addm d adi d adi m ii. subtra ction: sbc d sbcm d sub d su b m d sbi d sbim iii. bcd: daa d das z logi c ope r ati on instructio n s eor d eorm d eorim d or d orm d orim d an d d andm d a ndim z dat a t r a n smi ssi on i n st ru ct ions lda d st a d ldi z flow control instru ction s baz d bc d ba0 d ba1 d ba2 d ba3 d call d rt n w d rt n i d hal t d st op d jmp d tjmp the above a r e all of the instructio ns o f SH6610 se rie s , which a dd up to onl y 40 in numb e r , b u t never overl o ok the m ! a variety of co nsu m er ele c t r ical prod uct s on the market are cre a ted with them, e.g. cal c ulato r , remote c o ntroller , wat c h, toy , etc . 1-2 explanation of sy mbols before goin g to our su bje c t, we li st the sym bols th at may app ea r af terwards so that our rea ders can u nde rst and thi s boo k mo re easily . th e sy mbol s are li sted as follo ws: pc program counter ac ac cumulator cy ca rry flag mx dat a m e mory bbb ram ban k st s t ack tbr t able bran ch regi ste r x program addres s i immediate dat a ve r 1 . 0 3 / 3 6
s h 6 6 1 0 i n s t r u c t i o n s i n t r o d u c t i o n & logi c and | logi c or ^ logi c eor no w let? s ent er the world o f instru ction s of sh661 0 se rie s . ?let ?s g o ? f ve r 1 . 0 4 / 3 6
s h 6 6 1 0 i n s t r u c t i o n s i n t r o d u c t i o n 1-3 instructions for d a ta transmission during th e internal o p e ratio n of the system, da ta is transmit t ed rapidly a nd incessa n tly betwe en me morie s o r regi sters. this fast and in ce ssant tra nsmi s sion i s the po we r of syste m capability. SH6610 sy stem provides several in structions for data tr ansmission, as follows: ins t ruc t ion: ldi fun c tion: to load immedi ate dat a i to ?accumul ator? a nd ?dat a memory? format: instru ction code: ca rry flag: ope r ation: ldi mx d i 01 1 1 1 iiii xxx xxxx not af fec t ed ac , mx ? i explanation ldi is a very freque ntly used inst ru ction. it loads immediate d a t a i to accu mulator a n d dat a m e mo ry . ho weve r , du e to this 4-bit system , the pre s et rang e of the imme di ate dat a i is 00h ~ 0f h(0 ~ 15 ), and th at of mx is 00h~7f h . [ example ] l d i 2 0 h d 05 h a f t e r e x e c u t i o n : a c = 0 5 h content of dat a memo ry $20 h=05 h progr amming tip there isn ? t any sp eci a ll y define d re gi ster for u s e r s in sh66 10 system , but we can u s e it s powerful d a t a m e m o ry a s registe r s in ou r pro g ram designi ng. in the abo ve e x a m ple, i have use d dat a m e m o ry $20 h fo r a regi ste r . ho we ve r , if th ey a r e e x pressed o n ly b y a ddress an d without respe c tive n a m e s, the desi gn of the pro g ram will be very confusi ng. here ? s a tip for you: you can use the p s eu do-i n structio n equ to defin e each dat a a ddress. a a a e q u 2 0 h n a m e o f m e mo ry v a ri a b l e dat a memor y address pseud o- therefore, the ldi inst ru ction ca n also be written lik e this : l d i a a a d 05h ve r 1 . 0 5 / 3 6
s h 6 6 1 0 i n s t r u c t i o n s i n t r o d u c t i o n i n st ru ct ion: s t a fun c tion:to st ore the valu e of accu mulat o r to dat a me mory format: instru ction code: ca rry flag: ope r ation: st a mx d bbb 001 1 1 1bbb x xx xxxx not af fec t ed mx ? ac explanation st a loads the val ue o f accumul a tor to dat a m e mory . whe n executin g thi s in stru ction, cpu d o e s the tran smissio n only and th e ca rry flag is not af fected. [ example ] save the value of ac in $ 21h : l d i 2 0 h d 05 h ;ac=0 5h d $ 20h=0 5h s t a 2 1 h d 00 h ;$21h=0 5h : progr amming tip if operan d 2 is the immediate dat a i, then the prog ram can be written in the followin g wa ys: l d i 2 0 h , 0ah ; e x presse d in hex l d i 2 0 h , 10 ; e x presse d in decim al l d i 2 0 h , 1010 b ; e x presse d in binary i n st ru ct ion: l d a fun c tion: to load the value of dat a mem o ry to accum u lator format: instru ction code: ca rry flag: ope r ation: lda mx d bbb 001 1 1 0bbb x xx xxxx not af fec t ed ac ? mx explanation lda loa d s th e value of da t a memo ry to accumul a tor . this instru ction do es no t af fect the ca rry flag. ve r 1 . 0 6 / 3 6
s h 6 6 1 0 i n s t r u c t i o n s i n t r o d u c t i o n [ example ] load the valu e of $20h to ac : ldi 20h,0 5h ;$20h=0 5h,a c=05 h ldi 21h,0 fh ;$21h=0 fh,a c=0f h lda 20h,0 ;ac=0 5h : progr amming tip when writi ng a prog ra m , we often use la bel s a s jum p ing de stination s in the pro g ram . label n a m e s can b e define d by u s e r accordi ng to the followi ng rule s: i. a label m u stn ? t begin with num ber or sp a c e. ii. length of a label m u stn ? t exce ed 7 characte rs. only the first 7 chara c ters will be re cog n ized fo r label s e x ce eding that len g th. ve r 1 . 0 7 / 3 6
s h 6 6 1 0 i n s t r u c t i o n s i n t r o d u c t i o n 1-4 instructions for a r ithmetic operation sh66 10 se rie s provid e so me freque ntly used ar ithm e t ic (intege r) o peration instruction s , like: addition, subtractio n, bcd a d ju stment, etc. i n st ru ct ion: a dd fun c tion: to add up the val ues of dat a memo ry and accumulato r , and then sav e the re sult in the accu mul a tor format: instru ction code: ca rry flag: ope r ation: add mx d bbb 00001 0bbb xxx xxxx cy ac ? mx + a c explanation instru ctio n add a d d s up the value s of dat a mem o ry and a c cu mulator a nd saves the re sult in the a c cumul a tor . the add op e r ati on af fe ct s ca rry flag: wh en the re sult of add exc e eds 0fh, the ca rry flag is s e t to 1; otherwi se the value of cy is 0. therefo r e we ca n deci de wheth e r there? s a carry by the va lue of the ca rry flag af ter ad dition. [ example ] 05h +06 h : ldi 20h,0 5h ;$20h=0 5h,a c=05 h ldi 21h,0 6h ;$21h=0 6h,a c=06 h lda 20h,0 0h ;ac=0 5h add 21h,0 ;ac=0b h,cy =0,$2 1h = 0 6 h : [ example ] 0bh + 06h : ldi 20h,0b h ;$20h=0b h , a c=0bh ldi 21h,0 6h ;$21h=0 6h,a c=06 h lda 20h,0 0h ;ac=0b h,cy =0 a d d 2 1 h , 0 ; a c = 0 1 h , c y = 1 , $ 2 1 h = 0 6 h : i n st ru ct ion: a d d m fun c tion: to add up the val ues of dat a memo ry and accumulato r , and save the re sult in both the accumul a tor and the dat a memory format: instru ction code: ca rry flag: ope r ation: addm mx d bbb 00001 1bbb xxx xxxx cy ac , mx ? mx + ac ve r 1 . 0 8 / 3 6
s h 6 6 1 0 i n s t r u c t i o n s i n t r o d u c t i o n explanation instru ctio n addm a d d s up the valu es of dat a m e mory a nd a c cumul a tor a nd saves the re sult in b o th the accu mula tor an d the d a t a mem o ry . the addm ope ration af fect s ca rry flag: whe n the re sult of addm excee d s 0f h, the ca rry fla g is set to 1; otherwi se the value cy i s 0. therefore we can de cid e whethe r there? s a carry by the value of the carry flag af ter ad dition. [ example ] 05h +06 h : ldi 20h,0 5h ;$20h=0 5h,a c=05 h ldi 21h,0 6h ;$21h=0 6h,a c=06 h l d a 2 0 h , 0 0 h ; a c = 0 5 h addm 21h,0 ;ac=0b h,$2 1h=0b h ,cy=0 : [ example ] 0bh + 06h : ldi 20h,0b h ;$20h=0b h , a c=0bh ldi 21h,0 6h ;$21h=0 6h,a c=06 h l d a 2 0 h , 0 0 h ; a c = 0 b h , c y = 0 a d d m 2 1 h , 0 ; a c = 0 1 h , $ 2 1 h = 0 1 h , c y = 1 : progr amming tip when yo u are readi ng the exam ples, i sugge st tha t you call the m into ice af ter com p iling to watch the cha nge in e a c h of the re gi sters ste p by step. i n st ru ct ion: a dc fun c tion: to add up the val ue of dat a m e mory , carry flay and the value of accu mulato r , and then save the re sult in the ac cumulator format: instru ction code: ca rry flag: ope r ation: adc mx d bbb 00000 0bbb xxx xxxx cy ac ? mx + a c + cy explanation instru ctio n adc ad ds up the value of dat a memo ry , carry flag and the value of ve r 1 . 0 9 / 3 6
s h 6 6 1 0 i n s t r u c t i o n s i n t r o d u c t i o n accum u lato r , and saves th e re sult in the accu m u lato r . the adc ope ration af f e ct s the carry flag: when th e re sult of adc exce ed s 0 fh, the ca rry flag is set to 1; otherwise the value of c y is 0. theref ore we can d e cid e wheth e r there? s a carry by the value of the carry flag af ter addition. [ example ] 05h +06 h , cy=1 : ; c y = 1 ldi 20h,0 5h ;$20h=0 5h,a c=05 h ldi 21h,0 6h ;$21h=0 6h,a c=06 h l d a 2 0 h , 0 0 h ; a c = 0 5 h adc 21h,0 ;ac=0 c h,$2 1h=06 h ,cy = 0 : [ example ] 0bh + 06h , cy=0 : ; c y = 0 ldi 20h,0b h ;$20h=0b h , a c=0bh ldi 21h,0 6h ;$21h=0 6h,a c=06 h l d a 2 0 h , 0 0 h ; a c = 0 b h a d c 2 1 h , 0 ; a c = 0 1 h , $ 2 1 h = 0 6 h , c y = 1 : progr amming tip when carry i s n o t co n s ide r e d , yo u ? d better use add rathe r t han a dc, in ord e r to a v oi d extra un cert ai nty due to the addition of cy value (be c a u se cy ca n b e either 1 o r 0). v e r1 .0 10/ 36
s h 6 6 1 0 i n s t r u c t i o n s i n t r o d u c t i o n i n st ru ct ion: a d c m fun c tion: to add up the val ue of dat a m e mory , carry flag an d the value of accu mulato r , and then save the re sult in both the accumulato r and the dat a memo ry format: instru ction code: ca rry flag: ope r ation: adcm mx d bbb 00000 1bbb xxx xxxx cy ac , mx ? mx + a c + cy explanation instru ctio n adcm ad ds up the value of dat a memory , ca rry flag and the value of accum u lato r , and saves th e re sult in bot h the accum u lator an d the dat a mem o ry . the adcm ope ration af fect s the ca rry flag: wh en t he result of adcm exceed s 0f h, the carry flag is set to1; otherwi se the value of cy is 0. th eref o r e we ca n de cide wh e t her the r e? s a ca rry by the value of the carry flag af te r addition. [ example ] 05h +06 h , cy=1 : ; c y = 1 ldi 20h,0 5h ;$20h=0 5h,a c=05 h ldi 21h,0 6h ;$21h=0 6h,a c=06 h l d a 2 0 h , 0 0 h ; a c = 0 5 h adcm 21h,0 ;ac=0 c h,$2 1h =0 ch, cy= 0 : [ example ] 0bh + 06h , cy=0 : ; c y = 0 ldi 20h,0b h ;$20h=0b h , a c=0bh ldi 21h,0 6h ;$21h=0 6h,a c=06 h lda 20h,0 0h ;ac=0b h, a d c m 2 1 h , 0 ; a c = 0 1 h , $ 2 1 h = 0 1 h , c y = 1 : i n st ru ct ion: a d i fun c tion: to add up the val ue of dat a m e mory an d immediate dat a i, and then sa ve the result in accumul a to r format: instru ction code: ca rry flag: ope r ation: adi mx d i 01000 iiii xxx xxxx cy ac ? mx + i explanation instru ctio n adi adds u p the value of dat a memory and immedi ate dat a i, and save s the ve r 1 . 0 1 1 / 3 6
s h 6 6 1 0 i n s t r u c t i o n s i n t r o d u c t i o n re sult in accu mulato r . the adi operati on af fect s carry flag: when the result of adi exceed s 0fh, the carry flag is set to1; otherwi se the va lu e of cy is 0. therefo r e we ca n de cide wheth e r the r e ? s a ca rry by the val ue of the ca rry flag af ter additio n . [ example ] $20h=0 5h , i=04 h : ldi 20h,0 5h ;$20h=0 5h,a c=05 h,cy =0 a d i 2 0 h , 0 4 h ; a c = 0 9 h , $ 2 0 h = 0 5 h , c y = 0 : [ example ] $20h=0 ah , i=07h : ldi 20h,0a h ;$20h=0a h , a c=0ah,cy =0 a d i 2 0 h , 0 7 h ; a c = 0 1 h , $ 2 0 h = 0 a h , c y = 1 : i n st ru ct ion: a d i m fun c tion: to add up the val ue of dat a m e mory an d immediate dat a i, and then sa ve the result in both accum u lator a nd the dat a m e mo ry format: instru ction code: ca rry flag: ope r ation: a d i m m x d i 01001 iiii xxx xxxx cy ac , mx ? mx + i explanation instruction adim add s up the value of dat a memory and immediate dat a i, and saves th e re sult in both accumulato r and the dat a memory . the adim o peration af fect s carry flag: whe n the result of adim e x ceed s 0 f h, the ca rry fl ag is set to1; oth e rwise the val ue of cy i s 0. therefore we can de cid e b y the value of the ca rry flag af ter additio n whethe r there is a ca rry . [ example ] $20h=0 5h , i=04 h : ldi 20h,0 5h ;$20h=0 5h,a c=05 h a d i m 2 0 h , 0 4 h ; a c = 0 9 h , $ 2 0 h = 0 9 h , c y = 0 : [ example ] $20h=0 ah , i=07h : ldi 20h,0a h ;$20h=0a h , a c=0ah v e r1 .0 12/ 36
s h 6 6 1 0 i n s t r u c t i o n s i n t r o d u c t i o n a d i m 2 0 h , 0 7 h ; a c = 0 1 h , $ 2 0 h = 0 1 h , c y = 1 : i n st ru ct ion: d a a func tion: to adjust the valu e of dat a me mory to deci m al af ter addition, an d then save the result in both accu mulato r and the dat a memo ry format: instru ction code: ca rry flag: ope r ation: daa mx 1 1 001 01 10 x xx x xxx cy ac ; mx ? dec i mal , adjust ac for add explanation instru ctio n daa act s b y adjusting th e value of dat a memory to deci m al af ter addition an d saving the re sult to both accumul a tor a nd the dat a memo ry . it s adjusting m e thod is if the value of the dat a m e mo ry is g r eate r th an 9 or if cy = 1, the n ad d 6 to the dat a memo ry and s e t the c a rry flag to 1. [ example ] 06h + 05 h , and do daa adjustme n t : l d i 2 0 h , 0 6 h ; a c = 0 6 h , $ 2 0 h = 0 6 h l d i 2 1 h , 0 5 h ; a c = 0 5 h , $ 2 1 h = 0 5 h l d a 2 0 h , 0 ; a c = 0 6 h a d d 2 1 h , 0 ; a c = 0 b h , c y = 0 d a a 2 1 h ; a c = 0 1 h , $ 2 1 h = 0 1 h , c y = 1 : v e r1 .0 13/ 36
s h 6 6 1 0 i n s t r u c t i o n s i n t r o d u c t i o n i n st ru ct ion: s u b fun c tion: to subtra ct the value of accum u lator fro m the value of dat a m e mo ry , and then sa ve the result in the ac cumulator format: instru ction code: ca rry flag: ope r ation: sub mx d bbb 0001 1 0bbb xxx x xxx cy ac ? mx - ac explanation sub subtract s the value of accumulato r from the valu e of dat a me mory and sav e s the re sult in the a c cumul a tor . whe n exe c uti ng sub, if the value of d a t a memo ry is l e ss than th e value of accumulator , a ?borrow? will t a ke pl ace and cy will be set to 0. on the contrary , i f the value of dat a mem o ry is gre a ter th an the value of accumul a tor , bo rro w wil l not happe n and cy will be set to 1. therefo r e we ca n d e ci de by the value of cy wheth e r the r e i s a borro w af te r executio n of sub. besid e s, subtractio n in the syste m is do ne th rough additio n , i.e. when sub t ractin g a nu mbe r , it is actually addin g the num ber ? s bina ry compl e ment . [ example ] 06h - 05h : ldi 20h,0 5h ;ac=0 5 h,$ 2 0 h =05 h ldi 21h,0 6h ;ac=0 6 h,$ 2 1 h =06 h l d a 2 0 h , 0 ; a c = 0 5 h sub 21h,0 ;ac=1, cy=1, $21 h=06 h : [ example ] 05h - 06h : ldi 20h,0 5h ;ac=0 5 h,$ 2 0 h =05 h ldi 21h,0 6h ;ac=0 6 h,$ 2 1 h =06 h l d a 2 1 h , 0 ; a c = 0 6 h s u b 2 0 h , 0 ; a c = 0 f h , c y = 0 , $ 2 0 h = 0 5 h : v e r1 .0 14/ 36
s h 6 6 1 0 i n s t r u c t i o n s i n t r o d u c t i o n i n st ru ct ion: s u b m fun c tion: to subtra ct the value of accum u lator fro m the value of dat a m e mo ry , and then sa ve the result in both the accumulato r and the dat a memo ry format: instru ction code: ca rry flag: ope r ation: subm mx d bbb 0001 1 1bbb xxx x xxx cy ac , mx ? mx - ac explanation system movement of subm is alm o st the sam e as sub, it subt ra ct s current value of accum u lator f r om the val u e of dat a me mory an d saves the result in the accumulator as well as in the dat a memory . when exe c utin g subm, if the value of dat a memo ry is l e ss than the value of accumulator , a ?borrow? will t a ke pl ace and cy will be set to 0. on the contrary , i f the value of dat a mem o ry is gre a ter th an the value of accumul a tor , bo rro w wil l not happe n and cy will be 1. there f ore we ca n deci de by the value of cy whethe r there i s a borr o w af ter exe c utio n of subm. [ example ] 06h - 05 h : ldi 20h,0 5h ;ac=0 5 h,$ 2 0 h =05 h ldi 21h,0 6h ;ac=0 6 h,$ 2 1 h =06 h lda 20h,0 ;ac=0 5h su bm 2 1 h ,0 ;ac = 01 h , c y = 1 ,$ 21 h= 01h : [ example ] 05h - 06 h : ldi 20h,0 5h ;ac=0 5 h,$ 2 0 h =05 h ldi 21h,0 6h ;ac=0 6 h,$ 2 1 h =06 h l d a 2 1 h , 0 ; a c = 0 6 h subm 20h,0 ;ac=0f h,cy =0,$2 0 h = 0 f h : v e r1 .0 15/ 36
s h 6 6 1 0 i n s t r u c t i o n s i n t r o d u c t i o n i n st ru ct ion: s b c fun c tion: to subtra ct the value of accum u lator fro m the value of dat a m e mo ry , add ca rry fl ag, and then save the resu lt in the accumul a tor format: instru ction code: ca rry flag: ope r ation: sbc mx d bbb 00010 0bbb xxx xxxx cy ac ? mx - ac + cy explanation system mov e ment of sb c is to su btract the valu e of accum u la tor from th e value of dat a mem o ry , add the valu e of carry flag, and then sa ve the result i n the accumu lator . whe n executin g sbc, if the value of dat a memory is le ss than the value of accum u lat o r , a ?bo r row? will t a ke pla c e and the cy will be set to 0. on the cont rary , if th e value of dat a memory is gre a ter tha n the value of accum u lat o r , bo rrow will not hap pe n and th e cy will be 1. therefore we can d e ci de by the value of cy wheth e r there is a borrow af ter execution o f sbc. [ example ] cy=0 d 6 - 5 = ? : ; c y = 0 ldi 20h,0 5h ;ac=0 5 h,$ 2 0 h =05 h ldi 21h,0 6h ;ac=0 6 h,$ 2 1 h =06 h lda 20h,0 ;ac=0 5 h sbc 2 1 h ,0 ;ac = 01 h , c y = 0 ,$ 21 h= 06h : [ example ] cy=1 d 6 - 5=? : ;cy= 1 ldi 20h,0 5h ;ac=0 5 h,$ 2 0 h =05 h ldi 21h,0 6h ;ac=0 6 h,$ 2 1 h =06 h lda 20h,0 ;ac=0 5h sbc 2 1 h ,0 ;ac = 02 h , c y = 0 ,$ 21 h= 06h : i n st ru ct ion: s b c m fun c tion: to subtra ct the value of accum u lator fro m the value of dat a m e mo ry , add ca rry fl ag, and then save the resu lt in both the accu mulator a nd the dat a mem o ry format: instru ction code: ca rry flag: ope r ation: sbcm mx d bbb 00010 1bbb xxx xxxx cy ac , mx ? mx - ac + cy v e r1 .0 16/ 36
s h 6 6 1 0 i n s t r u c t i o n s i n t r o d u c t i o n explanation system movement of sbcm is to su btra ct the valu e of accum u l a tor from th e value o f dat a me mory , add the valu e of ca rry fla g , and the n save the re sul t in both the accum u lato r and dat a m e mory . when executin g s b cm, if the value of d a t a memo ry is l e ss than the value of accu mulato r , a ?b orrow? will t a ke pla c e and the cy will b e set to 0. on the contra ry , if the value of dat a m e mo ry is greater t han the val u e of accum u lat o r , bo rrow wil l not hap pen and the cy will be set to 1. therefo r e we can de cid e by the valu e of cy whet her th ere i s a borro w af ter executio n of sbcm. [ example ] cy=0 d 6 - 5=? : ; c y = 0 ldi 20h,0 5h ;ac=0 5 h,$ 2 0 h =05 h ldi 21h,0 6h ;ac=0 6 h,$ 2 1 h =06 h l d a 2 0 h , 0 ; a c = 0 5 h , c y = 0 sbc m 2 1 h ,0 ;ac = 01 h , c y = 0 ,$ 21 h= 01h : [ example ] cy=1 d 6 - 5=? : ;cy= 1 ldi 20h,0 5h ;ac=0 5 h,$ 2 0 h =05 h ldi 21h,0 6h ;ac=0 6 h,$ 2 1 h =06 h l d a 2 0 h , 0 ; a c = 0 5 h , c y = 1 s b c m 2 1 h , 0 ; a c = 0 2 h , c y = 0 , $ 2 1 h = 0 2 h : i n st ru ct ion: s b i fun c tion: to subtra ct the immediat e dat a i from the value of dat a memo ry , and then save the result in accumulato r format: instru ction code: ca rry flag: ope r ation: sbi mx d i 01010 iiii xxx xxxx cy ac ? mx - i explanation system movemen t of sbi is to subtract i mmediate d a t a i from the value of dat a memo ry , and save the re sult in accu mulato r . wh en exec uting sbi, if the value of the dat a memo ry is less than the immediate d a t a , a ?bo rro w? will t a ke place and cy will be set to 0. on th e v e r1 .0 17/ 36
s h 6 6 1 0 i n s t r u c t i o n s i n t r o d u c t i o n cont rary , if the value of dat a memory is gr eater than the immediate dat a, borrow will not happ en an d cy will be 1. therefo r e we ca n de ci d e by the valu e of cy whether there is a borro w af ter executio n of sbi. [ example ] $20h=0 5h , i=04 h : ldi 20h,0 5h ;$20h=0 5h,a c=05 h,cy =0 s b i 2 0 h , 0 4 h ; a c = 0 1 h , $ 2 0 h = 0 5 h , c y = 1 : [ example ] $20h=0 2h , i=07 h : ldi 20h,0 2h ;$20h=0 2h,a c=02 h,cy =0 sbi 20h,0 7h ;ac=0b h,$2 0h=02 h ,cy = 0 : i n st ru ct ion: s b i m fun c tion: to subtra ct imme diate dat a i from the value of dat a memo ry , and then save the result in both accu mulato r and the dat a memo ry format: instru ction code: ca rry flag: ope r ation: sbim m x d i 0101 1 iiii xxx xxxx cy ac , mx ? mx - i explanation system mov e ment of sb im is to subt ra ct immedi a t e dat a i fro m the value of dat a memo ry , and save the re sult in b o th a c cumul a tor a nd the dat a memo ry . when exe c utin g sbim, i f the value of dat a memory is less than the immediate dat a , a ?borrow? will t a ke place and cy will be set to 0. on the cont rary , if the va lue of dat a memo ry is g r eater th an th e immediate d a t a, borrow wil l not happe n and cy will b e 1. theref ore we ca n d e cid e by the value of cy wheth e r the r e is a borro w a f ter execution of sbim. [ example ] $20h=0 5h , i=04 h : ldi 20h,0 5h ;$20h=0 5h,a c=05 h s b i m 2 0 h , 0 4 h ; a c = 0 1 h , $ 2 0 h = 0 1 h , c y = 1 : v e r1 .0 18/ 36
s h 6 6 1 0 i n s t r u c t i o n s i n t r o d u c t i o n [ example ] $20h=0 2h , i=07 h : ldi 20h,0 2h ;$20h=0 2h,a c=02 h sbim 20h,0 7h ;ac=0b h,$2 0h=0b h ,cy=0 : i n st ru ct ion: d a s fun c tion: to adjust the valu e of dat a me mory to deci m al af ter subt ra ction, a nd save the result in accu mulator a nd the dat a m e mo ry format: instru ction code: ca rry flag: ope r ation: das mx 1 1 001 1010 xxx x xxx cy ac ; mx ? dec imal , adjust ac for sub explanation instru ction das act s by adjustin g the value of dat a memo ry to decimal af te r su btra ction and saving t he re sult to b o th accum u la tor and th e d a t a mem o ry . it s adju s ting method i s if the value of d a t a memory is greate r than 9 or if cy=0, then add 0ah to the dat a memory an d s e t cy to 0. [ example ] 05h - 06h , and do da s adjustme n t : ldi 20h,0 6h ;ac=0 6 h,$ 2 0 h =06 h ldi 21h,0 5h ;ac=0 5 h,$ 2 1 h =05 h l d a 2 0 h , 0 ; a c = 0 6 h s u b 2 1 h , 0 ; a c = 0 f h , c y = 0 d as 2 1 h ;ac = 09 h , $2 1h =0 9h ,c y= 0 : v e r1 .0 19/ 36
s h 6 6 1 0 i n s t r u c t i o n s i n t r o d u c t i o n 1-5 instructions for logic operation logi c instructions are essential to sy stem structu r e. SH6610 se rie s mcu provid e som e commo n logi c in structions. no w i ? m goin g to e x plain to you one by one in most det ail s , and a ssi st m y explanation with simpl e exampl e s , so that you can quickly unde rst and a c tio n theory of ea ch instructio n. i n st ru ct ion: a nd fun c tion: to do logic a nd o peration with the values of dat a m e mo ry and accu mu lator , an d then save t he re sult in the ac cumulator format: instru ction code: ca rry flag: ope r ation: and mx d bbb 001 10 1bbb xxx x xxx not af fec t ed ac ? mx & ac explanation in and operation, the resul t w ill be 1(t r ue) only if both of the two operands are 1(true). it s logic t a ble is as follo ws: logi c ope rati on t able fo r and a b a and b 0 0 0 0 1 0 1 0 0 1 1 1 however , in real inst ru ction the logic op era nd has 4 bit s rather than 1 bit. the inst r u ct io n a nd i s to and the valu es of dat a me mory with accum u lato r , a nd the re sult i s saved in the accum u lato r . [ example ] 06h & 05h : l d i 2 0 h , 0 1 1 0 b ; a c = 0 6 h , $ 2 0 h = 0 6 h ldi 21h,0 101b ;ac=0 5 h,$ 2 1 h =05 h and 20h,0 ;ac=0 100b,$ 20h=0 6h : v e r1 .0 20/ 36
s h 6 6 1 0 i n s t r u c t i o n s i n t r o d u c t i o n i n st ru ct ion: a n d m fun c tion: to do logi c a nd ope ratio n with the values of dat a memo ry and accu mulato r , and then save the re su lt in both the accu mulator a nd the dat a mem o ry format: instru ction code: ca rry flag: ope r ation: andm mx d bbb 001 10 1bbb xxx x xxx not af fec t ed ac , mx ? mx & ac explanation system movement of the instru ctio n andm i s al most the sa me as and, but saving th e ope ration result in dat a me mory as well as in ac cumulator . [ example ] 01 10b & 0101b : ldi 20h,0 1 1 0b ;ac=0 1 1 0 b,$20h=0 1 1 0b ldi 21h,0 101b ;ac=0 101b,$ 21h=0 101b andm 20h,0 ;ac=0 100b,$ 20h=0 100b : i n st ru ct ion: a ndi m fun c tion: to do logi c a n d ope ration wit h the valu e o f dat a m e mo ry and imme dia t e dat a i, an d then save the re sult in both accumulato r and the dat a memo ry format: instru ction code: ca rry flag: ope r ation: andim mx d i 01 1 10 iiii xxx xxxx not af fec t ed ac , mx ? mx & i explanation system movement of the instru ction a ndim i s to chang e ope ra nd 2 (a ccum ulator) of instructio n and to imme d i ate dat a i. this in st ru cti on is in imme diate mod e , so the add re ss of dat a memory can only be set to bank 0( $000 h ~ $07fh ). the operation re sult is save d in both accu mulator a nd the dat a m e m o ry . [ example ] $20h=01 10b , i=001 1 b : l d i 2 0 h , 0 1 1 0 b ; a c = 0 6 h , $ 2 0 h = 0 1 1 0 b andim 20h,0 01 1b ;ac=0 010b,$ 20h=0 010b : v e r1 .0 21/ 36
s h 6 6 1 0 i n s t r u c t i o n s i n t r o d u c t i o n progr amming tip andim it self has a spe c ial function ?ma s k? . when we ne ed to set a cert ain bi t to 0, we can c l ear this bit to 0 with andim like this : [ example ] clear bit 2 of $20h to 0 a n d i m 2 0 h d 10 1 1 b af ter execution: $20 h=x0xxb v e r1 .0 22/ 36
s h 6 6 1 0 i n s t r u c t i o n s i n t r o d u c t i o n i n st ru ct ion: o r fun c tion: to do logic o r ope ration wit h the values of dat a mem o ry and accu mu lator , an d then save t he re sult in the ac cumulator format: instru ction code: ca rry flag: ope r ation: o r m x d b bb 00101 0bbb xxx xxxx not af fec t ed ac ? mx | ac explanation in or operation, the resul t will be 1(true) if either one of the two ope ran d s is 1(tru e ). it s logic t a ble is as follo ws: logi c ope rati on t able fo r o r a b a o r b 0 0 0 0 1 1 1 0 1 1 1 1 however , in real inst ruction the l o gic op erand also h a s 4bit s rath er tha n 1 bit. the instruction or is to o r the values of dat a memo ry with accu mul a tor , and th e re sult is save d in the accum u lator . [ example ] 0001b | 0100b : ldi 20h,0 001b ;$20h=0 001 b,ac=00 01b ldi 21h,0 100b ;$21h=0 100 b,ac=01 00b or 20h,0 ;$20h=0 001 b,ac=01 01b : i n st ru ct ion: o r m fun c tion: to do logic o r ope ration wit h the values of dat a mem o ry and accumul a tor , and the n save the result in both the accumulato r and the dat a memo ry format: instru ction code: ca rry flag: ope r ation: orm mx d bbb 00101 1bbb xxx xxxx not af fec t ed ac , mx ? mx | ac v e r1 .0 23/ 36
s h 6 6 1 0 i n s t r u c t i o n s i n t r o d u c t i o n explanation system movement of the in stru ction o r m i s almo st the same a s o r , but saving t h e ope ration result in dat a me mory as well as in ac cumulator . [ example ] 0001b | 0100b : ldi 20h,0 001b ;$20h=0 001 b,ac=00 01b ldi 21h,0 100b ;$21h=0 100 b,ac=01 00b orm 20h,0 ;$20h=0 101 b,ac=01 01b : progr amming tip in program designi ng, if a cert ain bit of a variable need s to be set to 1 and the other bit s m u st not be a f fected, then this ca n be do ne by t he inst ru ction or. beca use any bit that has done or ope ration with 0 can ke ep it s origi nal value , while tho s e with 1 will ha ve the valu e of 1. ins t ruc t ion: orim fun c tion: to do logi c o r ope ration with the value o f dat a mem o ry and imme dia t e dat a i, an d then save the re sult in both accumulato r and the dat a memo ry format: instru ction code: ca rry flag: ope r ation: o r i m m x d i 01 101 iiii xxx xxxx not af fec t ed ac , mx ? mx | i explanation system movement of the instru ction orim is to do logic o r ope ration wit h the value o f dat a m e mo ry and imm edi ate da t a i, a nd save the re sult in b o th accum u lato r and th e dat a memo ry . this inst ru ction i s also in imm ediate mo de. [ exa mple ] set bit 3 of the value of $20h to 1 o r i m 2 0 h d 10 00b af ter exec ution: $20h = 1xxxb v e r1 .0 24/ 36
s h 6 6 1 0 i n s t r u c t i o n s i n t r o d u c t i o n i n st ru ct ion: e o r fun c tion: to do logic excl usive or ope ra tion with the value s of dat a memo ry and accumulato r , and the n sav e the re sult in the ac cumulator format: instru ction code: ca rry flag: ope r ation: eor mx d bbb 00100 0bbb xxx xxxx not af fec t ed ac ? mx ^ ac explanation system movement of eor is to do logic exclu s ive or operation with the value s of dat a memo ry and accum u lato r , and save the re sult in the a c cumul a tor . eor is usuall y referred to as exclusive or, becau se the operati on resu lt will be 1 only if the two opera n d s have dif f erent valu es; othe rwi s e the result will be 0. the logic t a ble for eor is a s foll ows: logi c ope rati on t able fo r eor a b a e o r b 0 0 0 0 1 1 1 0 1 1 1 0 [ example ] 001 1b ^ 0101b : ldi 20h,0 01 1b ;$20h=0 01 1b ,ac=0 0 1 1 b ldi 21h,0 101b ;$21h=0 101 b,ac=01 01b eor 20h,0 ;$20h=0 01 1b ,ac=0 1 1 0 b : v e r1 .0 25/ 36
s h 6 6 1 0 i n s t r u c t i o n s i n t r o d u c t i o n i n st ru ct ion: e o rm fun c tion: to do lo gic excl usive or op eratio n with the valu es of dat a mem o ry and accu mu lator , and the n save the re sult in both the accum u lator a n d the dat a m e mory format: instru ction code: ca rry flag: ope r ation: e o r m m x d bbb 00100 1bbb xxx xxxx not af fec t ed ac , mx ? mx ^ ac explanation system movement of the instructio n eorm is almost the sa me as eor, i.e. doing eor action with th e values of dat a memo ry and a c cumul a tor , but saving the op erat ion re sult in th e dat a mem o ry as well as in t he accu mulat o r . [ example ] 001 1b ^ 0101 b : ldi 20h,0 01 1b ;$20h=0 01 1b ,ac=0 0 1 1 b ldi 21h,0 101b ;$21h=0 101 b,ac=01 01b eorm 20h,0 ;$20h=0 1 1 0b ,ac=0 1 1 0 b : i n st ru ct ion: e o ri m fun c tion: to do logi c eo r operation with the value o f dat a me mory and imme dia t e dat a i, an d then save the re sult in both the accumul a tor and the dat a memo ry format: instru ction code: ca rry flag: ope r ation: eorim mx d i 01 100 iiii xxx xxxx not af fec t ed ac , mx ? mx ^ i explanation operan d 2 of the instructi on eo rim shoul d be immediate dat a. this instruction i s t o d o logic eor op eratio n with the value of d a t a memory and immedi ate dat a i, and to save th e re sult in both the accum u la tor and the d a t a memo ry . [ example ] $20h=0 01 1b d i= 01 01 b : ldi 20h,0 011b ;$20h=0 011 b,ac=00 11b eorim 20h,0 101b ;$20h=0 1 1 0b ,ac=0 1 1 0 b : v e r1 .0 26/ 36
s h 6 6 1 0 i n s t r u c t i o n s i n t r o d u c t i o n progr amming tip af ter readi ng all of the logic inst ru ctions, yo u may wond er why there ha ven ? t the ?n o t ? inst r u ct io n (in v e r se)? if there ha ve n ? t s u ch an in stru ction in sh66 10 se rie s , wh at can i do? don ? t worry , prog ram m i ng t i p is going to tell you how to use other instru ction s to perform th e not fu nctio n . the opera t ion of no t i s to chan ge 0 ? 1 or 1 ? 0 on e a ch bit. here, the eor in stru ct ion can h e lp us to g e t the in ve rsed valu e b y doi ng eo r op eratio n wit h imm ediate da t a (0f h ) and the va riabl e that wa nt s to be do ne not . y o u ? ll underst an d cle a rl y af ter readi ng the followin g exam ple. [ example ] do the ope ratio n not with the value of $2 0h (1 1 00b) e o r i m 2 0 h , 0 f h execution re su lt: $20h=00 1 1b,ac=0 0 1 1 b 1-6 instruc t ions for f l o w contr o l i n st ru ct ion: j m p fun c tion: to jump to a de si gnated a d d r e ss to exe c ute prog ram format: instru ction code: ca rry flag: ope r ation: j m p x 1 1 10p xxxx xxx xxxx not af fec t ed pc ? x(in clu de p) explanation instru ctio n jmp jump s to a desi gnated a ddress to execute prog ram. howeve r , addressi ng cap a bility of sh66 10 seri es cpu is limit ed to 4k wo rds (000 0h~0 fffh), so th e jumpin g ran g e of jmp ca n only rea c h 4 k (0fff h). addre s s bey ond 4k shall be re ached b y swit chin g ba nks. there? s det aile d explanatio n in later ch apters for how to swit ch ban ks. the jmp in st ru ct ion is simi lar t o t he go t o inst r u ct io n in basic program. [ exampl e ] pc= 4 0h , j u mp to 0e00h j m p 0 e 0 0 h e x e c u t i o n r e s u l t : p c = 0 e 0 0 h v e r1 .0 27/ 36
s h 6 6 1 0 i n s t r u c t i o n s i n t r o d u c t i o n [ exampl e ] j u mp to lable jmp loop ;jump to loop (pc ? 034 0h ) : o r g 0 3 4 0 h l o o p : n o p n o p : i n st ru ct ion: b a z fun c tion: if ac equ als 0 , then go to a desi gnate d add re ss t o execute pro g r am; othe rwi s e co ntinue to execute the next line format: instru ction code: ca rry flag: ope r ation: baz x 10010 xxxx xxx xxxx not af fec t ed pc ? x , if a c =0 explanation if the val ue of ac is 0, then af ter exec uting the baz instruction, pc will go to th e desi gnate d a ddress x to execute p r o g r am, t he ra n ge of x bein g from $0 00 h to $7ff h . i t contin ue s to execute the n e xt line if the value of ac is 1 [ example ] if ($20 h=$2 0h-1 )=00 h then goto i n c21 h ldi 20h,0 fh ;$20h=0 fh dec20 h : sbim 20h,0 1h ;ac,$20 h ? $20 h -1 b a z i n c 2 1 h ; i f a c = 0 j u m p t o inc21 h j m p d e c 2 0 h ; e l s e j u m p t o dec 2 0 h : inc21 h adim 21h,0 1h ;$21h+1 : i n st ru ct ion: b a 0 fun c tion: if bit 0 of ac is 1, then go to a desig nat ed add re ss t o execute prog ram; othe rwise co ntinue to execute th e next line format: instru ction code: ca rry flag: ope r ation: ba0 x 10100 xxxx xxx xxxx not af fec t ed pc ? x , if a c (0)= 1 v e r1 .0 28/ 36
s h 6 6 1 0 i n s t r u c t i o n s i n t r o d u c t i o n explanation if bit 0 of ac is 1, th en af ter executing ba0 instructio n, pc will go to the designat ed add re ss x to execute program, the ra ng e of x bei ng f r om $ 000 h to $7ff h or f r o m $080 0 h to $0fff h. it contin ue s to execute the n e xt line if bit 0 of ac is 0 . [ example ] if $20 h(bit 0)=1 then goto inc21 h : ldi 20h,0 fh ;$20h=0 fh,a c=0f h dec20 h : bim 20h,0 1h ;$20h,a c ? $ 20h -1 b a 0 i n c 2 1 h ; i f a c ( b i t 0 ) = 1 , j u m p t o i n c 2 1 h j m p d e c 2 0 h ; e l s e j u m p t o d e c 2 0 h : inc2 1h: adim 21h,0 1h ;$21h,a c ? $ 21h+1 i n st ru ct ion: b a 1 fun c tion: if bit 1 of ac is 1, then g o to de sign a t ed add re ss to execute pro g r am; othe rwi s e co ntinue to execute the next line format: instru ction code: ca rry flag: ope r ation: ba1 x 10101 xxxx xxx xxxx not af fec t ed pc ? x , if a c (1)= 1 explanation if bit 1 of ac is 1, th en af ter executing ba1 instructio n, pc will go to the designat ed add re ss x to execute program, the ra ng e of x bei ng f r om $ 000 h to $7ff h or f r o m $080 0 h to $0fff h. it contin ue s to execute the n e xt line if bit 1 of ac is 0 . [ example ] if $20h(bit 1)=1 then goto inc21 h : ldi 20h,0 fh ;$20h=0 fh,a c=0f h dec20 h : sbim 20h,0 1h ;$20h,a c ? $ 20h -1 b a 1 i n c 2 1 h ;ifac(bit1)= 1,jump to inc21h j m p d e c 2 0 h ; e l s e j u m p t o d e c 2 0 h : inc21 h : adim 21h,0 1h ;$21h,a c ? $ 21h+1 : v e r1 .0 29/ 36
s h 6 6 1 0 i n s t r u c t i o n s i n t r o d u c t i o n i n st ru ct ion: b a 2 fun c tion: if bit 2 of ac is 1, then g o to desig na ted add re ss to execute prog ram; othe rwise co ntinue to execute th e next line format: instru ction code: ca rry flag: ope r ation: ba2 x 101 10 xxxx x xx x xxx not af fec t ed pc ? x , if a c (2)= 1 explanation if bit 2 of ac is 1, th en af ter executing ba2 instructio n, pc will go to the designat ed add re ss x to execute p r og ram, the rang e of x being from $0 00 h to $7ffh o r fro m $0800 h or $0fff h. it contin ue s to execute the n e xt line if bit 1 of ac is 0 . [ example ] if $20 h(bit 2)=1 then goto inc21 h : ldi 20h,0 fh ;$20h=0 fh,a c=0f h dec20 h : sbim 20h,0 1h ;$20h,a c ? $ 20h -1 ba2 inc21h ;if ac(bit2)= 1 , jump to inc21h j m p d e c 2 0 h ; e l s e j u m p t o d e c 2 0 h : inc2 1h: adim 21h,0 1h ;$21h,a c ? $ 21h+1 : i n st ru ct ion: b a 3 fun c tion: if bit 3 of ac is 1, then g o to de sign a t ed add re ss to execute pro g r am; othe rwi s e co ntinue to execute the next line format: instru ction code: ca rry flag: ope r ation: ba3 x 101 1 1 xxxx x xx x xxx not af fec t ed pc ? x , if a c (3)= 1 explanation if bit 3 of ac is 1, th en af ter executing ba3 instruct ion, pc will go to the designat ed add re ss x to execute program, the ra ng e of x bei ng f r om $ 000 h to $7ff h or f r o m $080 0 h to $0fff h. it contin ue s to execute the n e xt line if bit 1 of ac is 0 . v e r1 .0 30/ 36
s h 6 6 1 0 i n s t r u c t i o n s i n t r o d u c t i o n [ example ] if $20 h(bit 3)=1 then goto inc21 h : ldi 20h,0 fh ;$20h=0 fh,a c=0f h dec20 h sbim 20h,0 1h ;$20h,a c ? $ 20h -1 b a 3 i n c 2 1 h ; i f a c ( b i t 3 ) = 1 , j u m p t o i n c 2 1 h j m p d e c 2 0 h ; e l s e j u m p t o d e c 2 0 h : inc2 1h: adim 21h,0 1h ;$21h,a c ? $ 21h+1 : i n st ru ct ion: b c fun c tion: if cy is 1, then go to desi gnated a ddre ss to execute pro g ra m; otherwise co ntin ue to execute the next line format: instru ction code: ca rry flag: ope r ation: b c x 1001 1 xxxx x xx x xxx cy pc ? x , if cy= 1 explanation i f c y i s 1 , then af ter ex ecutin g in stru ction bc, pc will go to the desi gnate d add re ss x t o execute p r og ram, the ran ge of x being from $000 h to $7ffh. it continue s to execute the next line if cy is n o t 1. the in structi on bc is of ten u s e d af te r ad dition or subt ra ction t o deci de wh eth e r there is a carry or bo rro w . y ou sho u l d espe cially not e that for addition, cy is set to 1 when there i s a ca rry , while for subt ra ction cy is set to1 when the r e i s n? t any borro w . therefore you sho u ld be careful wh e n d ealing with program flows. [ example ] if cy=1 then g o to inc2 0h : ldi 20h,0 fh ;$20h=0 fh,a c=0f h,cy=0 inc2 0h : sbim 20h,0 1h ;$20h,a c ? $ 20h -1 bc inc20h ;if cy= 1 ,jump to inc20h : v e r1 .0 31/ 36
s h 6 6 1 0 i n s t r u c t i o n s i n t r o d u c t i o n i n st ru ct ion: t j mp fun c tion:uncondition ally go to the address com p o s ed by (pc1 1 ~ pc8), tbr and ac value to execute pro g ra m format: instru ction code: ca rry flag: ope r ation: tjmp 11 11 0 1 11 1 1 1 1 11 11 not af fec t ed explanation the de stinati on add re ss for instructio n tjmp is co mpo s ed by pc? s bit 8 ~ bit 1 1 , tb r and ac valu e (plea s e refer to instru ction r t nw for p r ogram examp l e). example: pc=30 0 h, tbr=01h, ac=0 2 h , then the ru le for com p o s ing a de stinat ion addres s is as follows : add re ss=pc(bit8~bit 1 1 ) tbr ac if: p c = 3 00h t b r = 0 1 h a c = 0 2 h then the d e st ination ad dre ss i s : 3 1 2 h instru ction: call fun c tion: to call a sub p rogram format: instru ction code: ca rry flag: ope r ation: call x 1 1 000 xxxx x xx x xxx not af fec t ed st ? cy ;pc , pc ? x (not includ e p) explanation instruction call is u s e d to call a su bprogram. f i r s t i t s a v e s the values of cy and pc+ 1 to st ack for returning to the calling program, then g o e s to the d esi g nated a dd r e s s x ( $ 000 0h ~ $07ff h or $0800 h ~ $0fff h) to execute p r og ra m. instructi ons r t nw o r r t ni ca n be use d to retu rn to the calli ng prog ram. when usi n g call to call a su bprog ra m, you sho u l d esp e ci ally note how many layers of st a ck have al rea dy been use d , becau se s h 66 10 se rie s only provide 4-laye r st a c ks. if more than 4 laye rs are used, serious erro r will be o c cu rre d when returning to the calling program! v e r1 .0 32/ 36
s h 6 6 1 0 i n s t r u c t i o n s i n t r o d u c t i o n i n st ru ct ion: r t n w func tion: to return to the calling program, h ? tb r, l ? ac format: instru ction code: ca rry flag: ope r ation: rt n w h d l 1 10 10 00 0h h hh 1 1 1 1 not af fec t ed pc ? st , tbr ? hh hh , ac ? 111 1 explanation r t nw is an instructio n to get dat a from st ack to pc for returnin g to the calling pro g ra m , and at the same time put the value of h into tb r and the value of l into ac. this instructi o n is of ten u s ed to get st ation a ry dat a. [ example ] t o get dat a from rom a d d r e ss 3 0 2 h tbr equ oeh temp equ 20h : : 001a ldi tbr d 0 0 h ;put index value (hi gh nib b l e ) 0 into tbr. 001b ldi temp d 02 ;put index value (lo w nib b l e ) 2 into ac 001 c call 300 h ;call su bp rog r am. 001 d : : : o r g 3 0 0 h 0300 tjmp ; get destination add re ss $ 030 2h a c cording to (pc1 1~ pc8), t br,ac 0301 r t nw 00h,0 1h 0302 r t nw 00h,0 2h ;return to mai n pro g ra m, h ? tb r,l ? ac 0303 r t nw 04h,0 5h 0304 r t nw 09h,0 8h 0305 : i n st ru ct ion: r t ni func tion: to return from interrupt or sub p ro gra m format: instru ction code: ca rry flag: ope r ation: rt n i 1 10 10 10 00 0 00 000 0 cy cy ;pc ? st v e r1 .0 33/ 36
s h 6 6 1 0 i n s t r u c t i o n s i n t r o d u c t i o n explanation instru ction r t ni is mainly used for retu rnin g from interrupt or sub p ro gra m . it fills cy and pc with values of st ack (cy an d returni ng add re ss) wh en returning. what? s the dif f eren ce b e twee n r t ni a nd r t nw? w e can find that whe n ret u rni ng by r t nw , only the returning ad d r e ss in the st ack is fetche d into pc, but cy value is not fetched. and r tnw fetche s anoth e r two valu es (h ? tbr, l ? ac ), whi c h r t ni doe s n o t do. therefore you ca n cho o se from the two in stru ction s acco rdi ng to your ne eds. [ example ] t o exchang e two numb e rs 000e 1 tbr equ 0eh 0020 2 regx equ 20h 0021 3 regy equ 21h 0022 4 temp equ 22h 5 ;********** ** ******** * 0005 780e 12 reset : ldi temp ,00h ;set temp=00h 0006 7 920 13 ldi regx,02 h ;set regx =0 2 h 0007 7a 21 14 ldi regy ,04h ;set regy =0 4 h 0008 c00a 15 call sw apxy ; ;call subprogram 17 ;******** *** ******** *** 000a 3820 18 sw apxy lda regx,00h ;ac=02h 000b 3 c 22 19 st a temp ,00h ;temp=02 h 000 c 382 1 20 lda regy ,00h ;ac=0 4h 000 d 3c20 21 st a regx,00 h ;regx=0 4 h 000e 38 22 22 lda temp ,00h ;ac=0 2 h 000f 3 c 2 1 23 st a regy ,00h ;reg2 = 02 h 0010 d40 0 24 r t ni ;return to mai n pro g ra m v e r1 .0 34/ 36
s h 6 6 1 0 i n s t r u c t i o n s i n t r o d u c t i o n i n st ru ct ion: h a l t fun c tion: cp u to be halt from wo rki n g format: instru ction code: ca rry flag: ope r ation: hal t 1 10 1 1 0 000 0 00 000 0 not af fec t ed no explanation af ter executing inst ruction ha l t , cpu will be ha lt while it s surrounding circuit (counter , oscillation circuit) continues working. the instruct ion ha l t is usu ally use d to stop cp u temporarily in orde r to save powe r . in hal t mode, when any of t he system inte rru pt s o c curs, cpu will be relea s ed from hal t m ode a nd co ntinue t o wo rk. [ example ] halt pro g ram, to ena ble port b interrupt to wak e up the program iex equ 00h ;interru pt ena ble re giste r irq equ 01h ;interru pt req u ire flag por t b equ 09h ;i/o port b : ldi por t b,0f h ;set port b = ? high ? ldi iex,0001b ;enable p o rt i n terrupt ldi irq,00 h ;clea r interrup t require flag h a l t ; s y s t e m c p u h a l t n o p : i n st ru ct ion: s t op fun c tion: to stop the whol e chip (i ncl udin g oscillation cir c uit) format: instru ction code: ca rry flag: ope r ation: st op 1 10 1 1 1 000 0 00 000 0 not af fec t ed no explanation executing inst ru ct ion st op will stop the whole chip from working, incl uding oscillation c i rc uit. only por t interrupt and external interrupt can relea s e cpu from s t op mode, so you must en able an inte rrupt befo r e e n terin g st op mode , otherwise the system can?t be wak ed up from st op mode. v e r1 .0 35/ 36
s h 6 6 1 0 i n s t r u c t i o n s i n t r o d u c t i o n [ example ] stop prog ra m, to enable port b interrupt to wa ke up the progra m iex equ 00h ;interru pt ena ble re giste r irq equ 01h ;interru pt req u ire flag p o r t b e q u 0 9 h ; i / o p o r t b : ldi por t b,0f h ;set port b = ? high ? ldi iex,0001b ;enable p o rt i n terrupt ldi irq,00 h ;clea r interrup t require flag s t o p ; a l l s y s t e m i s ? s t o p ? n o p : i n st ru ct ion: n o p fun c tion: to do nothing format: instru ction code: ca rry flag: ope r ation: nop 11 11 11 11 11 1 11 11 not af fec t ed no explanation instruction nop mea n s doing n o thin g in it s in stru ction cycle a nd it is of ten use d for tim e delay . beca use it does n o thing wh en executin g, you don?t worry if it will af fect any current st at u s . v e r1 .0 36/ 36


▲Up To Search▲   

 
Price & Availability of SH6610

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X